package drongo.model.propertys
{
	import drongo.model.core.IProperty;
	import drongo.model.core.ISerialization;
	import drongo.model.core.IValue;
	import drongo.model.events.ModelEvent;
	import drongo.model.values.CollectionValue;
	
	public class CollectionProperty extends CollectionValue implements IProperty,ISerialization
	{
		private var key:String;
		public function CollectionProperty(key:String)
		{
			super();
			this.key=key;
		}
		
		public function GetKey():String{
			return this.key;
		}
		
		override protected function SendEvent(newValue:*, oldValue:*):void
		{
			if(this.hasEventListener(ModelEvent.VALUE_CHANGED)){
				this.dispatchEvent(ModelEvent.Create(ModelEvent.VALUE_CHANGED,oldValue,value,this.key));
			}
		}
		
		override public function Equality(value:IValue):Boolean{
			if(!(value is CollectionProperty)){
				return false;
			}
			var property:IProperty=value as CollectionProperty;
			if(this.key!=property.GetKey()){
				return false;
			}
			return super.Equality(value);
		}
	}
}